# -*- coding:utf-8 -*-
#!/usr/bin/python
import re
from splinter import Browser
from sql_cases import *
from urlparse import urlparse,urlunparse
''' 
        initialize detect lists
'''
detect_sql_lists={}  
detect_xss_lists={}  

class Basis(object):
    
    def __init__(self,browser,url):
        self.browser=browser
        self.url=url
        
    def parseQuery(self,type):
            if type=="xss":
                detect_lists=detect_xss_lists
            elif type=="sql":
                detect_lists=detect_sql_lists
            u=urlparse(self.url)
            param_dicts={}
            bak_dicts={}
            if u.query:
                  params_list=u.query.split("&")
                  for param in params_list:
                      semi=param.split('=')
                      param_dicts[semi[0]]=semi[1]
                 
                  bak_dicts=param_dicts.copy()
                  base_url=urlunparse((u.scheme,u.netloc,u.path,'','',''))
                  if base_url in detect_lists.keys():
                       for param in param_dicts.keys():
                           if param in detect_lists[base_url]:
                               param_dicts.pop(param)
                  else:
                      detect_lists[base_url]=[]
                      
                  for key in param_dicts.keys():
                          detect_lists[base_url].append(key)
                          
            return bak_dicts,param_dicts
            
        
